<?php

class Curl{
    private $_header = [];
    private $_params = [];
    private $_url = '';

    public function get($url, $params = [])
    {
        $this->_url = $url;
        $this->_params = $params;
        return $this->_request('GET');
    }

    public function post($url, $params = [])
    {
        $this->_url = $url;
        $this->_params = $params;
        return $this->_request('POST');
    }

    public function setHeader($header = [])
    {
        $this->_header = $header;
        return true;
    }

    private function _request($method = 'GET')
    {
        $ch = curl_init();
        if (!empty($this->_header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_header);
        }
        if ($method == 'GET') {
            $this->_url .= '?'.http_build_query($this->_params);
        } else if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_params);
        }
        curl_setopt($ch, CURLOPT_URL, $this->_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $response = curl_exec($ch);
        curl_close($ch);

        return $response;
    }
}